package cn.q3.service.impl;

import cn.q3.mapper.EmpMapper;
import cn.q3.pojo.Emp;
import cn.q3.service.EmpService;
import cn.q3.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    EmpMapper empMapper;

    @Override
    public PageUtil<Emp> findAll(int pageNo, int size) {

        PageUtil<Emp> pageUtil = new PageUtil<>(pageNo, size, findCount());

        int offset = (pageUtil.getPageNo() - 1) * pageUtil.getSize();
        List<Emp> emps = empMapper.findAll(offset, pageUtil.getSize());
        pageUtil.setDatas(emps);
        return pageUtil;
    }

    /**
     * 查询总记录
     *
     * @return
     */
    @Override
    public int findCount() {
        return empMapper.findCount();
    }
}
